/**
 * Created by gakuin on 5/24/16.
 */
var path = require('path');
var webpack = require('webpack');
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'WebApp');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');
var nodeModulePath=path.resolve(ROOT_PATH,'node_modules');
var HtmlwebpackPlugin = require('html-webpack-plugin');
module.exports = {
    devtool:false,
    entry: {
        main: ['./WebApp/index.js'],
        vendor:['babel-polyfill','immutable','react',"react-redux","react-router","react-slick","redux-immutable"]
        //vendor:['babel-polyfill','react',"react-redux","react-slick"]
    },
    output: {
        path: 'build',
        publicPath:'/build/',
        filename: '[name].[hash].js',
        chunkFilename: "[id].[chunkhash].js"
    },
    resolve:{
        //当requrie的模块找不到时，添加这些后缀
        extentions:["",".js",".jsx",".es6",'.css','.png','.jpg'],
        //让webpack不需要搜索可以直接处理的文件
        alias:{
            'react-dom':path.join(nodeModulePath,'/react-dom/dist/react-dom.min'),
            //'react':path.join(nodeModulePath,'/react/dist/react.min'),
            'redux':path.join(nodeModulePath,'/redux/dist/redux.min'),
            'react-redux':path.join(nodeModulePath,'/react-redux/dist/react-redux.min'),
            //'jquery':path.join(nodeModulePath,'/jquery/dist/jquery.min'),
            'immutable':path.join(nodeModulePath,'/immutable/dist/immutable.min')
        }
    },
    module: {
        //没有依赖的文件可以直接处理
        noParse:[path.join(nodeModulePath,'/react/dist/react.min'),
            path.join(nodeModulePath,'/immutable/dist/immutable.min'),
            path.join(nodeModulePath,'/redux/dist/redux.min')
        ],
        loaders: [
            {
                test: /\.jsx?$/,
                loader: 'babel',
                //include: ROOT_PATH,
                exclude: /node_modules/,
                query: {
                    //添加两个presents 使用这两种presets处理js或者jsx文件
                    presets: ['es2015', 'react']
                }
            },
            {
                test: /\.css$/,
                loaders: ['style', 'css', 'sass'],
                include: ROOT_PATH
            },
            {
                test: /\.(png|jpg)$/,
                loader: 'url?limit=1&name=[path][name].[ext]'
            }
        ],postLoaders: [
            {
                test: /\.js$/,
                loaders: ['es3ify-loader']
            }
        ]
    },
    plugins: [
        new webpack.DefinePlugin({ "process.env": { NODE_ENV: JSON.stringify("production") } }),
        new webpack.optimize.CommonsChunkPlugin('vendor','vendor'+new Date().getTime()+".js"),
        new HtmlwebpackPlugin({
        template: path.resolve(APP_PATH, 'index.html'),
        filename: 'app.html',
        chunks: ['main','vendor'],
        inject: 'body',
        minify:{    //压缩HTML文件
            removeComments:true,    //移除HTML中的注释
            collapseWhitespace:false    //删除空白符与换行符
        }
    },new webpack.optimize.UglifyJsPlugin(
            {
                sourceMap:false,
                output:{
                    comments:false
                },
                compress:{
                    warnings:false
                }
            }
        )
    )

    ]
};